package com.guchenbo.study.aop;

import com.guchenbo.dubbo.undress.service.EchoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @Author guchenbo
 * @Date 2019/8/16.
 */
@Service
@Transactional
public class UserServiceImpl implements UserService, InitializingBean, ApplicationContextAware, DisposableBean {
    @Resource
    private TxServiceA txServiceA;
    @Autowired
    private TxServiceB txServiceB;
    @DubboReference
    private EchoService echoService;
    @Resource
    private Gcb gcb;

    @Value("${test.k}")
    private String k;
    private String name;

    public UserServiceImpl(String name) {
        this.name = name;
    }

    public UserServiceImpl() {
        System.out.println("构造器");
    }

    @Override
    public void user() {
        System.out.println("in user");
    }

    @Override
    public void error() {
        System.out.println("in error");
        throw new RuntimeException();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext");
    }

    @PostConstruct
    public void init() {
        System.out.println("@PostConstruct");
    }

    @PreDestroy
    public void dis() {
        System.out.println("@PreDestroy");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("destroy");
    }
}
